package com.heima.controller.user_service;

import com.heima.pojo.entity.Partner;
import com.heima.pojo.vo.PartnerByIdVo;
import com.heima.pojo.vo.PartnerPageVo;
import com.heima.service.PartnerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/api/user-service/partner")
public class PartnerController {
    @Autowired
    private PartnerService partnerService;

    /**
     * 合作商分页搜索
     * @param pageIndex
     * @param pageSize
     * @param name
     * @return
     */
    @GetMapping("/search")
    public PartnerPageVo pagePartner(@RequestParam(value = "pageIndex",required = false ) Integer pageIndex,
                                     @RequestParam(value = "pageSize",required = false )Integer pageSize,
                                     @RequestParam(value = "name",required = false )String name){
       log.info("合作商分页查询参数： {} {} {}",pageIndex,pageSize,name);
        PartnerPageVo partnerPageVo =  partnerService.pagePartner(pageIndex,pageSize,name);
        return partnerPageVo;
    }
    /**
     * 新增合作商
     */
    @PostMapping
    public Boolean save(@RequestBody Partner partner){
        log.info("新增合作商信息 {}",partner);
        Boolean result =partnerService.save(partner);
        return result;
    }
    /**
     * 通过id获取合作商详情
     */
    @GetMapping("/{id}")
    public PartnerByIdVo getPartById(@PathVariable String id){
      log.info("查询合作商的id {} ",id);
        PartnerByIdVo partnerByIdVo = partnerService.getPartById(id);
      return partnerByIdVo;
    }
    /**
     * 修改合作商信息
     */
    @PutMapping("/{id}")
    public Boolean update(@PathVariable String id, @RequestBody Partner partner){
        log.info("修改合作商的参数：id {} ",id);
       Boolean result = partnerService.update(id,partner);
        return result;
    }
    /**
     * 删除合作商
     */
    @DeleteMapping("/{id}")
    public Boolean delete(@PathVariable String id){
        return partnerService.delete(id);
    }

    /**
     * 获取合作商数量
     * @return
     */
    @GetMapping("/count")
    public Integer getNodeCount(){
        Integer count = partnerService.getPartnerCount();
        return count;
    }

}




















